<template>

  <div class="tree-tools">
    <!-- 用了一个行列布局 -->
    <el-row type="flex" justify="space-between" align="middle" style="height: 40px">
      <el-col>
        <!-- 作用于插槽 -->
        <span>{{ treeNode.name }}</span>
      </el-col>
      <el-col :span="4">
        <el-row type="flex" justify="end">
          <!-- 两个内容 -->
          <el-col>{{ treeNode.manager }}</el-col>
          <el-col>
            <!-- 下拉菜单 element -->
            <el-dropdown @command="onDropdownCommand">
              <span>
                操作<i class="el-icon-arrow-down" />
              </span>
              <!-- 下拉菜单 -->
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="add">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="!treeNode.root" command="edit">查看部门</el-dropdown-item>
                <el-dropdown-item v-if="!treeNode.root" command="del">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { delDapartmentComoany } from '@/api/dapartment'
export default {
  filters: {},
  components: {},
  props: {
    treeNode: {
      type: Object,
      required: true
    }
  },
  data() {
    return {

    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 下拉选择事件
    onDropdownCommand(command) {
      if (command === 'del') {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          // 删除组织部门
          await delDapartmentComoany(this.treeNode.id)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.$emit('on-companyList')
        })
      } else if (command === 'add') {
        // 打开弹出层
        this.$emit('on-add', this.treeNode)
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.tree-tools {
  width: 100%;
}
</style>
